import 'package:aero_frisbee/app/state/app_cache_state.dart';
import 'package:aero_frisbee/core/tools/af_log_manager.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import '../login/af_login_page.dart';
import 'app_tab_page.dart';

class AppLaunchPage extends ConsumerStatefulWidget {
  const AppLaunchPage({super.key});
  @override
  ConsumerState<ConsumerStatefulWidget> createState() => _AppLaunchPageState();
}

class _AppLaunchPageState extends ConsumerState<AppLaunchPage> {
  @override
  Widget build(BuildContext context) {
    ref.listen(curEngineFutureProvider, (previousData, newData) {
      print("xxx curEngineFutureProvider $newData");
    });
    final appState = ref.watch(appCacheServiceProvider);
    return appState.maybeWhen(
      orElse: () => const AFLoginPage(),
      data: (data) => data.maybeWhen(
        logined: (_) => AppTabPage(
          key: Keys.tabKey,
        ),
        orElse: () => const AFLoginPage(),
      ),
    );
  }

  @override
  void initState() {
    WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
      AFLogPvManger.stat(page: AFLogPages.launch);
    });

    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  void didUpdateWidget(AppLaunchPage oldWidget) {
    super.didUpdateWidget(oldWidget);
  }

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
  }
}
